<template>
  <div class="detail-container" v-if="homestay">
    <!-- 返回按钮 -->
    <div class="back-button">
      <el-button @click="goBack">
        <el-icon><ArrowLeft /></el-icon> 返回
      </el-button>
    </div>
    
    <!-- 民宿名称和操作 -->
    <div class="homestay-header">
      <h1 class="homestay-title">{{ homestay.name }}</h1>
      <div class="homestay-actions">
        <el-button 
          :type="isFavorite ? 'warning' : 'info'"
          @click="toggleFavorite"
        >
          <el-icon><Star v-if="isFavorite" /><StarFilled v-else /></el-icon>
          {{ isFavorite ? '已收藏' : '收藏' }}
        </el-button>
        <el-button type="primary" @click="scrollToBooking">立即预订</el-button>
      </div>
    </div>
    
    <!-- 民宿评分和地址 -->
    <div class="homestay-meta">
      <div class="meta-item">
        <el-rate v-model="homestay.rating" disabled text-color="#ff9900"></el-rate>
        <span class="rating-text">{{ homestay.rating }}分 ({{ reviews.length }}条评价)</span>
      </div>
      <div class="meta-item">
        <el-icon><Location /></el-icon>
        <span>{{ homestay.address }}</span>
      </div>
    </div>
    
    <!-- 民宿图片 -->
    <div class="homestay-images">
  <el-carousel :interval="5000" arrow="always" height="400px">
    <el-carousel-item v-for="(image, index) in homestay.images" :key="index">
      <img :src="image.img" :alt="`${homestay.name} - 图片${index + 1}`" class="carousel-image" />
    </el-carousel-item>
  </el-carousel>
</div>
    
    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 民宿信息 -->
      <div class="content-left">
        <div class="custom-sections">
          <!-- 民宿简介部分 -->
          <div class="custom-section">
            <div class="section-header">
              <h2>民宿简介</h2>
            </div>
            <div class="section-content">
              <div class="content-block">
                <h3>基本信息</h3>
                <p>{{ homestay.description }}</p>
              </div>
              
              <div class="content-block">
                <h3>房屋类型</h3>
                <p>{{ homestay.type }}</p>
              </div>
              
              <div class="content-block">
                <h3>配套设施</h3>
                <div class="facilities-list">
                  <span v-for="(facility, index) in homestay.facilities" :key="index" class="facility-tag">
                    {{ facility.name }}
                  </span>
                </div>
              </div>
              
              <div class="content-block">
                <h3>入住规则</h3>
                <p>{{ homestay.rules }}</p>
              </div>
            </div>
          </div>
          
          <!-- 用户评价部分 -->
          <div class="custom-section">
            <div class="section-header">
              <h2>用户评价</h2>
            </div>
            <div class="section-content">
              <!-- 添加评论表单 -->
              <div class="add-review-form" v-if="isLoggedIn">
                <h3>发表评论</h3>
                <el-form :model="reviewForm" :rules="reviewRules" ref="reviewFormRef">
                  <el-form-item prop="rating">
                    <el-rate
                      v-model="reviewForm.rating"
                      :texts="['很差', '较差', '一般', '不错', '很好']"
                      show-text
                    ></el-rate>
                  </el-form-item>
                  <el-form-item prop="content">
                    <el-input
                      type="textarea"
                      v-model="reviewForm.content"
                      :rows="4"
                      placeholder="请分享您的入住体验..."
                    ></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" @click="submitReview">发表评论</el-button>
                  </el-form-item>
                </el-form>
              </div>
              <el-alert
                v-else
                title="请登录后发表评论"
                type="info"
                :closable="false"
                style="margin-bottom: 20px;"
              >
                <template #default>
                  <el-button type="primary" size="small" @click="router.push('/login')">
                    去登录
                  </el-button>
                </template>
              </el-alert>
              
              <div class="reviews-container" v-if="reviews.length > 0">
                <div class="review-item" v-for="review in reviews" :key="review.id">
                  <div class="review-header">
                    <div class="reviewer-info">
                      <img :src="review.avatar" :alt="review.username" class="reviewer-avatar" />
                      <div>
                        <h4>{{ review.username }}</h4>
                        <span class="review-date">{{ review.time }}</span>
                      </div>
                    </div>
                    <div class="review-rating">
                      <el-rate v-model="review.rating" disabled text-color="#ff9900"></el-rate>
                    </div>
                  </div>
                  <div class="review-content">
                    {{ review.content }}
                  </div>
                </div>
              </div>
              <div class="no-reviews" v-else>
                暂无评价
              </div>
            </div>
          </div>
        </div>
        
        <!-- 附近推荐 -->
        <div class="nearby-recommendations">
          <h2 class="section-title">附近民宿推荐</h2>
          <div class="recommendations-grid">
            <el-card 
              v-for="item in nearbyHomestays" 
              :key="item.id" 
              class="homestay-card" 
              shadow="hover" 
              @click="navigateToDetail(item.id)"
            >
              <div class="homestay-image">
                <img :src="item.img" :alt="item.name" />
                <div class="homestay-price">¥{{ item.price }}/晚</div>
              </div>
              <div class="homestay-info">
                <h3 class="homestay-name">{{ item.name }}</h3>
                <div class="homestay-meta">
                  <span class="homestay-area">
                    <el-icon><Location /></el-icon>
                    {{ item.area }}
                  </span>
                  <el-rate 
                    v-if="item.rating"
                    v-model="item.rating" 
                    disabled 
                    :max="5"
                    :colors="['#ff9900', '#ff9900', '#ff9900']"
                    class="homestay-rating"
                  ></el-rate>
                </div>
                <p class="homestay-description">{{ item.description }}</p>
              </div>
            </el-card>
          </div>
        </div>
      </div>
      
      <!-- 预订卡片 -->
      <div class="content-right">
        <el-card class="booking-card" id="booking-section">
          <div class="booking-card-header">
            <h2>预订信息</h2>
            <div class="price-info">
              <span class="price">¥{{ homestay.price }}</span> / 晚
            </div>
          </div>
          
          <el-form :model="bookingForm" :rules="bookingRules" ref="bookingFormRef">
            <!-- 日期选择 -->
            <div class="form-section">
              <h4 class="form-section-title">选择日期</h4>
              <el-form-item prop="dateRange">
                <el-date-picker
                  v-model="bookingForm.dateRange"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="入住日期"
                  end-placeholder="退房日期"
                  :disabled-date="disabledDate"
                  style="width: 100%"
                  @change="calculateTotalPrice"
                ></el-date-picker>
              </el-form-item>
              <div class="form-tips">
                <el-icon><InfoFilled /></el-icon>
                入住时间：14:00后，退房时间：12:00前
              </div>
            </div>

            <!-- 入住信息 -->
            <div class="form-section">
              <h4 class="form-section-title">入住信息</h4>
              <el-form-item prop="guestCount" label="入住人数">
                <el-input-number
                  v-model="bookingForm.guestCount"
                  :min="1"
                  :max="homestay.capacity || 10"
                  style="width: 100%"
                ></el-input-number>
                <div class="form-tips" v-if="homestay.capacity">
                  <el-icon><InfoFilled /></el-icon>
                  最多可住{{ homestay.capacity }}人
                </div>
              </el-form-item>

              <el-form-item prop="contactName" label="联系人">
                <el-input v-model="bookingForm.contactName" placeholder="请输入入住人姓名"></el-input>
              </el-form-item>

              <el-form-item prop="contactPhone" label="手机号码">
                <el-input v-model="bookingForm.contactPhone" placeholder="请输入联系电话"></el-input>
              </el-form-item>

              <el-form-item prop="notes" label="备注">
                <el-input
                  type="textarea"
                  v-model="bookingForm.notes"
                  placeholder="如有特殊要求请在此说明（可选）"
                  :rows="3"
                ></el-input>
              </el-form-item>
            </div>
            
            <!-- 费用明细 -->
            <div class="form-section" v-if="bookingForm.dateRange && bookingForm.dateRange.length === 2">
              <h4 class="form-section-title">费用明细</h4>
              <div class="price-details">
                <div class="price-row">
                  <span>房费（¥{{ homestay.price }} x {{ bookingDays }}晚）</span>
                  <span>¥{{ subtotal }}</span>
                </div>
                <div class="price-row">
                  <span class="price-label">
                    服务费
                    <el-tooltip content="包含平台服务费和清洁费用" placement="top">
                      <el-icon><QuestionFilled /></el-icon>
                    </el-tooltip>
                  </span>
                  <span>¥{{ serviceFee }}</span>
                </div>
                <div class="price-total">
                  <span>总价</span>
                  <span class="total-amount">¥{{ totalPrice }}</span>
                </div>
              </div>
            </div>

            <!-- 预订须知 -->
            <div class="form-section booking-notes">
              <h4 class="form-section-title">预订须知</h4>
              <ul class="notes-list">
                <li>如需变更或取消，请提前24小时联系客服</li>
                <li>请爱护房间内设施，损坏需照价赔偿</li>
              </ul>
            </div>
            
            <el-form-item>
              <el-button type="primary" style="width: 100%" @click="submitBooking" :disabled="!isLoggedIn || !canBook">
                {{ isLoggedIn ? (canBook ? '立即预订 ¥' + totalPrice : '请选择日期') : '请先登录' }}
              </el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </div>
  </div>
  
  <div v-else class="loading-container">
    <el-skeleton :rows="10" animated />
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import request from '@/utils/request'
// 保留mock数据作为备选
// import { homestayList, reviews as mockReviews } from '../mock'
import { ElMessage } from 'element-plus'
// 导入图标
import { 
  ArrowLeft, 
  Star, 
  StarFilled, 
  Location, 
  InfoFilled, 
  QuestionFilled 
} from '@element-plus/icons-vue'


// 路由
const router = useRouter()
const route = useRoute()

// 民宿数据
const homestay = ref(null)
const reviews = ref([])
const loading = ref(true)

// 收藏状态
const isFavorite = ref(false)

// 用户登录状态
const isLoggedIn = ref(false)

// 预订表单
const bookingFormRef = ref(null)
const bookingForm = ref({
  dateRange: [],
  guestCount: 1,
  contactName: '',
  contactPhone: '',
  notes: ''
})

// 预订表单验证规则
const bookingRules = {
  dateRange: [
    { type: 'array', required: true, message: '请选择入住日期范围', trigger: 'change' }
  ],
  guestCount: [
    { required: true, message: '请选择入住人数', trigger: 'change' },
    { 
      validator: (rule, value, callback) => {
        if (homestay.value && homestay.value.capacity && value > homestay.value.capacity) {
          callback(new Error(`入住人数不能超过${homestay.value.capacity}人`));
        } else {
          callback();
        }
      }, 
      trigger: 'change' 
    }
  ],
  contactName: [
    { required: true, message: '请输入联系人姓名', trigger: 'blur' }
  ],
  contactPhone: [
    { required: true, message: '请输入联系电话', trigger: 'blur' },
    { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
  ]
}

// 禁用日期（今天之前的日期）
const disabledDate = (time) => {
  return time.getTime() < Date.now() - 8.64e7 // 8.64e7 = 24 * 60 * 60 * 1000
}

// 入住天数
const bookingDays = computed(() => {
  if (!bookingForm.value.dateRange || bookingForm.value.dateRange.length !== 2) {
    return 0
  }
  
  const startDate = new Date(bookingForm.value.dateRange[0])
  const endDate = new Date(bookingForm.value.dateRange[1])
  const diffTime = Math.abs(endDate - startDate)
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
  
  return diffDays
})

// 小计
const subtotal = computed(() => {
  return homestay.value ? homestay.value.price * bookingDays.value : 0
})

// 服务费
const serviceFee = computed(() => {
  return Math.round(subtotal.value * 0.1) // 10% 服务费
})

// 总价
const totalPrice = computed(() => {
  return subtotal.value + serviceFee.value
})

// 是否可以预订
const canBook = computed(() => {
  return bookingForm.value.dateRange && 
         bookingForm.value.dateRange.length === 2 && 
         bookingDays.value > 0
})

// 附近推荐（同一地区的其他民宿）
const nearbyHomestays = ref([])

// 评论表单
const reviewFormRef = ref(null)
const reviewForm = ref({
  rating: 5,
  content: ''
})

// 评论表单验证规则
const reviewRules = {
  rating: [
    { required: true, message: '请选择评分', trigger: 'change' }
  ],
  content: [
    { required: true, message: '请输入评论内容', trigger: 'blur' },
    { min: 5, message: '评论内容至少5个字符', trigger: 'blur' }
  ]
}

// 获取民宿详情
const fetchHomestayDetail = async () => {
  const homestayId = route.params.id
  if (!homestayId) {
    ElMessage.error('民宿ID不存在')
    router.push('/')
    return
  }
  
  loading.value = true
  
  try {
    // 调用API获取民宿详情
    const res = await request.get(`/homestays/detail/${homestayId}`)
    
    // 处理返回的数据
    homestay.value = res.data.data
    console.log('获取民宿详情1:', homestay.value.images)
    
    // 调整入住人数默认值和最大值
    if (homestay.value.capacity && homestay.value.capacity < bookingForm.value.guestCount) {
      bookingForm.value.guestCount = 1;
    }
    
    // 获取民宿评价
    fetchHomestayReviews(homestayId)
    
    // 检查是否已收藏
    checkFavoriteStatus(homestayId)
    
    // 获取附近推荐
    fetchNearbyHomestays()
    // 更新浏览量
    updateViewCount(homestayId)
  } catch (error) {
    console.error('获取民宿详情失败:', error)
    // 使用mock数据作为备选
    // fallbackToMockData(homestayId)
  } finally {
    loading.value = false
  }
}
// 更新浏览量
const updateViewCount = async (homestayId) => {
  try {
    await request.post(`/homestays/view/${homestayId}`)
  } catch (error) {
    console.error('更新浏览量失败:', error)
  }
}
// 使用mock数据作为备选
// const fallbackToMockData = (homestayId) => {
//   // 从mock数据中找到对应ID的民宿
//   const mockHomestay = homestayList.find(item => item.id == homestayId)
  
//   if (mockHomestay) {
//     homestay.value = mockHomestay
//     reviews.value = mockReviews.filter(item => item.homestayId == homestayId)
//     console.log('使用模拟数据:', mockHomestay)
//   } else {
//     ElMessage.error('未找到该民宿')
//     router.push('/')
//   }
// }

// 获取民宿评价
const fetchHomestayReviews = async (HomestayId) => {
  try {
    const res = await request.get(`/reviews/list/${HomestayId}`)
    reviews.value = res.data.data || []
  } catch (error) {
    console.error('获取评价失败:', error)
    // 使用mock数据作为备选
    // reviews.value = mockReviews.filter(item => item.homestayId == homestayId)
  }
}

// 检查是否已收藏
const checkFavoriteStatus = async (homestayId) => {
  // 检查用户是否登录
  const token = localStorage.getItem('token')
  if (!token) {
    isLoggedIn.value = false
    isFavorite.value = false
    return
  }
  
  isLoggedIn.value = true
  console.log(JSON.parse(localStorage.getItem('user')).id);
  
  try {
    const res = await request.post(`/favorites/isCol`, {
      homestayId: parseInt(homestayId),
      userId: JSON.parse(localStorage.getItem('user')).id
    })

    console.log('检查收藏状态:', res.data.data);
    
    isFavorite.value = res.data.data || false
  } catch (error) {
    console.error('检查收藏状态失败:', error)
    isFavorite.value = false
  }
}

// 收藏/取消收藏
const toggleFavorite = async () => {
  if (!isLoggedIn.value) {
    ElMessage.warning('请先登录')
    router.push('/login')
    return
  }
  
  const homestayId = homestay.value.id
  
  try {
    if (isFavorite.value) {
      // 取消收藏
      const res = await request.post(`/favorites/unCol`, {
      homestayId: parseInt(homestayId),
      userId: JSON.parse(localStorage.getItem('user')).id
    })
    if (res.data.code === '200') {
      ElMessage.success('已取消收藏')
      }

    } else {
      // 添加收藏
      const res = await request.post(`/favorites/add`, {
      homestayId: parseInt(homestayId),
      userId: JSON.parse(localStorage.getItem('user')).id
    })
      if (res.data.code === '200') {
        ElMessage.success('收藏成功')
      }

    }
    
    
    // 更新收藏状态
    isFavorite.value = !isFavorite.value
  } catch (error) {
    console.error('操作收藏失败:', error)
    ElMessage.error('操作失败，请稍后再试')
  }
}

// 获取附近推荐民宿
const fetchNearbyHomestays = async () => {
  if (!homestay.value) return
  
  try {
    const area = homestay.value.area
    
    const res = await request.get('/homestays/related', {
      params: {
        area
      }
    })
    
    nearbyHomestays.value = res.data.data || []

    console.log('获取附近民宿:', nearbyHomestays.value);
    
  } catch (error) {
    console.error('获取附近民宿失败:', error)
    // 使用模拟数据作为备选
    // nearbyHomestays.value = homestayList
    //   .filter(item => item.area === homestay.value.area && item.id !== homestay.value.id)
    //   .slice(0, 3)
  }
}

// 提交预订
const submitBooking = async () => {
  if (!isLoggedIn.value) {
    ElMessage.warning('请先登录')
    router.push('/login')
    return
  }
  
  bookingFormRef.value.validate(async (valid) => {
    if (valid) {
      if (!bookingForm.value.dateRange || bookingForm.value.dateRange.length !== 2) {
        ElMessage.warning('请选择入住日期')
        return
      }
      
      // 检查入住人数是否超过最大容纳人数
      if (homestay.value.capacity && bookingForm.value.guestCount > homestay.value.capacity) {
        ElMessage.warning(`入住人数不能超过${homestay.value.capacity}人`)
        return
      }
      
      const startDate = formatDate(bookingForm.value.dateRange[0])
      const endDate = formatDate(bookingForm.value.dateRange[1])
      
      try {
        // 构建预订数据
        const bookingData = {
          homestayId: homestay.value.id,
          startDate,
          endDate,
          userId: JSON.parse(localStorage.getItem('user')).id,
          days: bookingDays.value,
          totalPrice: totalPrice.value,
          guestCount: bookingForm.value.guestCount,
          contactName: bookingForm.value.contactName,
          contactPhone: bookingForm.value.contactPhone,
          notes: bookingForm.value.notes,
          name: homestay.value.name,
        }
        
        // 发送请求（现在注释掉以避免实际API调用）
        await request.post('/bookings/add', bookingData)
        
        ElMessage.success('预订成功')
        router.push('/user/bookings')
      } catch (error) {
        console.error('预订失败:', error)
        ElMessage.error('预订失败，请稍后再试')
      }
    }
  })
}

// 日期格式化工具函数
const formatDate = (date) => {
  if (!date) return '';
  
  const d = new Date(date);
  const year = d.getFullYear();
  const month = String(d.getMonth() + 1).padStart(2, '0');
  const day = String(d.getDate()).padStart(2, '0');
  
  // 新增：时分秒（默认补零）
  const hours = String(d.getHours()).padStart(2, '0');
  const minutes = String(d.getMinutes()).padStart(2, '0');
  const seconds = String(d.getSeconds()).padStart(2, '0');
  
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};

// 返回上一页
const goBack = () => {
  router.back()
}

// 跳转到预订区域
const scrollToBooking = () => {
  document.getElementById('booking-section').scrollIntoView({ behavior: 'smooth' }) // 滚动到预订区域
}

// 导航到其他民宿详情
const navigateToDetail = (id) => {
  if (id !== Number(route.params.id)) {
    router.push(`/homestay/${id}`)
  }
}

// 计算总价
const calculateTotalPrice = () => {
  // 通过计算属性自动计算
}

// 提交评论
const submitReview = async () => {
  if (!isLoggedIn.value) {
    ElMessage.warning('请先登录')
    router.push('/login')
    return
  }

  try {
    await reviewFormRef.value.validate()
    
    const reviewData = {
      homestayId: parseInt(route.params.id),
      userId: JSON.parse(localStorage.getItem('user')).id,
      rating: reviewForm.value.rating,
      content: reviewForm.value.content
    }
    
    const res = await request.post('/reviews/add', reviewData)
    
    if (res.data.code === '200') {
      ElMessage.success('评论发表成功')
      // 重置表单
      reviewForm.value.rating = 5
      reviewForm.value.content = ''
      // 刷新评论列表
      fetchHomestayReviews(route.params.id)
    } else {
      ElMessage.error(res.data.msg || '评论发表失败')
    }
  } catch (error) {
    ElMessage.warning('评论发表失败，请输入至少5个字')
  }
}

// 组件挂载时执行
onMounted(() => {
  // 检查用户是否登录
  const token = localStorage.getItem('token')
  isLoggedIn.value = !!token
  
  // 获取民宿详情
  fetchHomestayDetail()
})
</script>

<style scoped>
.detail-container {
  padding-bottom: 3rem;
}

.back-button {
  margin-bottom: 1rem;
}

.homestay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.homestay-title {
  font-size: 1.8rem;
  margin: 0;
}

.homestay-meta {
  display: flex;
  flex-wrap: wrap;  /* 允许换行 */
  gap: 2rem;        /* 添加间距 */
  margin-bottom: 1.5rem;
}

.meta-item {
  display: flex;
  align-items: center;
  color: #666;
}

.rating-text {
  margin-left: 0.5rem;
}

.homestay-images {
  margin-bottom: 2rem;
  border-radius: 8px;
  overflow: hidden;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.main-content {
  display: grid;                    /* 使用 grid 布局 */
  grid-template-columns: 1fr 350px; /* 两列等分 */
  gap: 24px;
  align-items: start;                /* 对齐方式 */
}

.content-left {
  width: 100%;
}

.content-right {
  position: sticky;
  top: 20px;
  height: fit-content;
}

.booking-card {
  width: 100%;
}

.custom-sections {
  display: flex;
  flex-direction: column;  /*设置子元素的排列方向为垂直方向（从上到下）*/
  gap: 2rem;                /*设置子元素之间的间距*/
  margin-bottom: 2rem;
}

.custom-section {
  border: 1px solid #EBEEF5;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);  /* 添加阴影 */
  background-color: #fff;
  overflow: hidden;
}

.section-header {
  background-color: #f5f7fa;
  padding: 15px 20px;
  border-bottom: 1px solid #EBEEF5;  /* 添加底部边框 */
}

.section-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #333;
  font-weight: 500;
}

.section-content {
  padding: 20px;
  height: auto;
  overflow: visible;  /* 设置为可见 */
}

.content-block {
  margin-bottom: 1.5rem;  /* 添加间距 */
}

.content-block:last-child {
  margin-bottom: 0;
}

.content-block h3 {
  margin: 0 0 1rem 0;  /* 添加间距 */
  font-size: 1.2rem;   /* 设置字体大小 */
  color: #333;       /* 设置字体颜色 */
}

.content-block p {
  margin: 0.5rem 0;
  line-height: 1.8;
  color: #666;
  font-size: 14px;
  white-space: pre-wrap;  
  word-break: break-word; /* 自动换行 */
}

.facilities-list {
  display: flex;
  flex-wrap: wrap; 
  gap: 0.5rem;
}

.facility-tag {
  background-color: #f5f5f5;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 0.9rem;
}

.reviews-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.review-item {
  border-bottom: 1px solid #eee;
  padding-bottom: 1.5rem;
}

.review-item:last-child {
  border-bottom: none;
}

.review-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.reviewer-info {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.reviewer-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.review-date {
  color: #999;
  font-size: 0.8rem;
}

.review-content {
  line-height: 1.6;
  color: #333;
}

.no-reviews {
  text-align: center;
  padding: 2rem;
  color: #999;
}

.booking-card {
  position: sticky;
  top: 20px;
  margin-bottom: 2rem;
}

.booking-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.price-info {
  color: #666;
}

.price {
  font-size: 1.5rem;
  color: #ff6b6b;
  font-weight: bold;
}

.booking-price-calculation {
  margin: 1.5rem 0;
  border-top: 1px solid #eee;
  padding-top: 1rem;
}

.price-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.8rem;
  color: #666;
}

.price-total {
  display: flex;
  justify-content: space-between;
  padding-top: 0.8rem;
  margin-top: 0.8rem;
  border-top: 1px solid #eee;
  font-weight: bold;
  font-size: 1.1rem;
}

.nearby-recommendations {
  margin-top: 3rem;
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  position: relative;
  padding-left: 15px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 5px;
  height: 20px;
  width: 5px;
  background-color: #ff6b6b;
  border-radius: 3px;
}

.recommendations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.homestay-card {
  border: 1px solid #ebeef5;
  transition: all 0.3s ease;
  height: 100%;
}

.homestay-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.homestay-image {
  position: relative;
  height: 200px;
  overflow: hidden;
  border-radius: 8px 8px 0 0;
}

.homestay-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.homestay-card:hover .homestay-image img {
  transform: scale(1.05);
}

.homestay-price {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: bold;
  font-size: 16px;
}

.homestay-info {
  padding: 16px;
}

.homestay-name {
  margin: 0;
  font-size: 18px;
  color: #303133;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.homestay-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.homestay-area {
  color: #606266;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.homestay-rating {
  transform: scale(0.8);
  transform-origin: right;
}

.homestay-description {
  color: #909399;
  font-size: 14px;
  line-height: 1.4;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  height: 40px;
}

.loading-container {
  padding: 2rem;
}

.add-review-form {
  background-color: #f9f9f9;
  padding: 20px;
  border-radius: 8px;
  margin-bottom: 30px;
}

.add-review-form h3 {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 1.2rem;
  color: #333;
}

.form-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid #eee;
}

.form-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.form-section-title {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  margin: 0 0 16px 0;
}

.form-tips {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.price-details {
  background-color: #f8f9fa;
  padding: 16px;
  border-radius: 8px;
}

.price-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  color: #606266;
  font-size: 14px;
}

.price-label {
  display: flex;
  align-items: center;
  gap: 4px;
}

.price-total {
  display: flex;
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid #dcdfe6;
  font-weight: bold;
  font-size: 16px;
}

.total-amount {
  color: #ff6b6b;
  font-size: 20px;
}

.notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.notes-list li {
  position: relative;
  padding-left: 16px;
  margin-bottom: 8px;
  color: #606266;
  font-size: 14px;
}

.notes-list li:before {
  content: "•";
  position: absolute;
  left: 0;
  color: #909399;
}

.notes-list li:last-child {
  margin-bottom: 0;
}

@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
  }
  
  .content-right {
    position: relative;
    top: 0;
    order: -1;
  }
}
</style> 